package com.ccx.demo.business.code.service;

import com.alibaba.fastjson.JSON;
import com.ccx.demo.business.code.entity.TabCodeExample;
import com.utils.IAutoTask;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

//import static com.ccx.demo.config.init.AppInit.getCacheManager; // 若使用缓存需要解开代码

/**
 * 服务接口实现类：测试案例表
 *
 * @author 谢长春 on 2022-02-16 V20220301
 */
@Slf4j
@Service
@Validated
@RequiredArgsConstructor
public class CodeExampleAutoTaskService
        implements IAutoTask {
    private final CodeExampleService service;

    @Override
    public void call(String args) {
        service.forEachExample1(list -> {
            list.forEach(row -> {
                try {
                    log.info(JSON.toJSONString(row));
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            });
        });
        service.forEachExample2(
                new TabCodeExample(),
                list -> {
                    list.forEach(row -> {
                        try {
                            log.info(JSON.toJSONString(row));
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                        }
                    });
                }
        );
    }
}
